package com.sniff.atp.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author zwg
 * @class PasswordUtil
 * @date 2023/12/4 10:30
 */
public class PasswordUtil {

    public static String getEncryptionPassword(Integer systemSource, String unencryptedPassword, String salt) {
        String password2Md5 = null;
        if (systemSource.equals(1)) {
            password2Md5 = DigestUtils.md5Hex(unencryptedPassword + salt);
        } else if (systemSource.equals(2)) {
            if(salt!=null){
                password2Md5 = DigestUtils.md5Hex(unencryptedPassword + salt);
            }else {
                password2Md5 = DigestUtils.md5Hex(unencryptedPassword);
            }
        }
        return password2Md5;
    }

    public static boolean comparePassword(Integer systemSource, String unencryptedPassword, String password,String salt) {
        String encryptionPassword = getEncryptionPassword(systemSource, unencryptedPassword, salt);
        return password.equals(encryptionPassword);
    }

}